package top.lishuoboy.jdbc.a8dbcp;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.List;
import java.util.Properties;

/**
 * @author lishuoboy
 * @date 2021-12-20 23:55
 */
@Slf4j
public class A8Druid {
    public static void main(String[] args) throws Exception {
        Properties props = new Properties();
        props.load(ResourceUtil.getStream("druid.properties"));
        DataSource ds = DruidDataSourceFactory.createDataSource(props);
        Connection conn = ds.getConnection();
        System.out.println(conn);

        List<Connection> list = ListUtil.list(false);
        for (int i = 0; i < 10000; i++) {
            try {
//                list.add(JDBCUtil.getConn());
                list.add(ds.getConnection());
                System.out.println(i);
            } catch (Exception e) {
                log.error("异常,i=={}", i, e);
                break;
            }
        }
        log.error("list.size()=={}", list.size());


    }
}